package com.java.computeronline.controller;

import java.util.List;

import com.java.computeronline.model.blo.CategoryBLO;
import com.java.computeronline.model.entity.Category;
import com.opensymphony.xwork2.ActionSupport;


@SuppressWarnings("serial")
public class CategoryAction extends ActionSupport{
	private CategoryBLO categoryBLO;
	private List<Category> categoryList;
	private Category category;
	private Category parentCategory;
	private Long id;
	private boolean status;

	public CategoryAction(){
		categoryBLO = new CategoryBLO();
	}

	public String execute(){
		categoryList = categoryBLO.list();
		return SUCCESS;
	}

	public String add(){
		try{
			Category category = getCategory();			
			if(isStatus()){
				category.setStatus(1);
			}else{
				category.setStatus(0);
			}
			categoryBLO.add(category);
		}catch(Exception ex){
		}
		return SUCCESS;
	}

	public String delete() {
		categoryBLO.delete(getId());
		return SUCCESS;
	}

	public String edit(){
		try{
			Category category = getCategory();
			if(isStatus()){
				category.setStatus(1);
			}else{
				category.setStatus(0);
			}
			categoryBLO.update(category);
		}catch(Exception ex){
			ex.printStackTrace();
		}
		return SUCCESS;
	}

	public List<Category> getCategoryList() {
		return categoryList;
	}

	public void setCategoryList(List<Category> categoryList) {
		this.categoryList = categoryList;
	}

	public Category getCategory() {
		return category;
	}

	public void setCategory(Category category) {
		this.category = category;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Category getParentCategory() {
		return parentCategory;
	}

	public void setParentCategory(Category parentCategory) {
		this.parentCategory = parentCategory;
	}

	public boolean isStatus() {
		return status;
	}

	public void setStatus(boolean status) {
		this.status = status;
	}


}
